home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / RCSC.ZIP / LIB51 / ITOU.C < prev    next >
Text File  |  1997-01-12  |  625b  |  24 lines

  1. /*
  2. ** itou -- convert nbr to unsigned decimal string of width sz
  3. **         right adjusted, blank filled; returns str
  4. **
  5. **        if sz > 0 terminate with null byte
  6. **        if sz = 0 find end of string
  7. **        if sz < 0 use last byte for data
  8. */
  9. itou(nbr, str, sz)  int nbr;  char str[];  int sz;  {
  10.   int lowbit;
  11.   if(sz>0) str[--sz]=NULL;
  12.   else if(sz<0) sz = -sz;
  13.   else while(str[sz]!=NULL) ++sz;
  14.   while(sz) {
  15.     lowbit=nbr&1;
  16.     nbr=(nbr>>1)&32767;  /* divide by 2 */
  17.     str[--sz]=((nbr%5)<<1)+lowbit+'0';
  18.     if((nbr=nbr/5)==0) break;
  19.     }
  20.   while(sz) str[--sz]=' ';
  21.   return str;
  22.   }
  23.  
  24.